#pragma once
#include <iostream>
#include <string>
#include <cstdio>
#include <pthread.h>

typedef void*(*fun_t)(void*);

class ThreadData
{
public:
    void* args_;
    std::string name_;
};
class Thread
{
public:
    Thread(int num,fun_t callback,void* args)
        :func_(callback)
    {
        char namebuffer[64];
        snprintf(namebuffer,sizeof namebuffer,"thread-%d",num);
        name_ = namebuffer;
        tData_.args_ = args;
        tData_.name_ = name_;
    }

    void start()
    {
        pthread_create(&tid_,nullptr,func_,(void*)&tData_.args_);
    }

    void join()
    {
        pthread_join(tid_,nullptr);
    }

    std::string name()
    {
        return name_;
    }

    ~Thread()
    {}
private:
    std::string name_;
    ThreadData tData_;
    pthread_t tid_;
    fun_t func_;
};
